public class Test {
    public static void main(String[] args) throws InterruptedException {
        Object object1 = new Object();
        Object object2 = new Object();
        Object object3 = new Object();
        Thread t1 = new Thread(()->{
            synchronized (object3){
                object3.notify();
                synchronized (object1) {
                    for (int i = 0; i < 10; i++) {
                        System.out.print ("A");
                        try {
                            object1.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (object1) {
                    object1.notify();
                    System.out.print("B");
                    synchronized (object2){
                        try {
                            object2.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        Thread t3 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (object2){
                    object2.notify();
                    System.out.println("C");
                    synchronized (object3){
                        try {
                            object3.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        t1.start();
        Thread.sleep(500);
        t2.start();
        Thread.sleep(500);
        t3.start();
        Thread.sleep(500);
    }
}

